﻿<?php
class EditActionController extends ActionController {

    public function run() {
        $articleMapper = new ArticleMapper();
        $editArt = $articleMapper->getArticleByID($this->params['id']);
        
        if(!($editArt->isOwner($this->user->id))){
            $this->redirect('index');
        }
    
        if($this->isPost()) {
            $editArticle = new Article($this->getPost());
            $newArt = $articleMapper->editArticle($editArticle);

            if (!isset($newArt->notice)) {
                $this->redirect('index');
            } else {
                $this->view->editArt = $newArt;
            }
        } else { 
            $this->view->editArt = $editArt;
        }
        $this->view->setRenderTemplate('edit.phtml');
    }
}

?>